/**
 * 
 */
package fr.univ_tln.inf9.exaplanning.api.cours;

import java.util.Date;

import javax.swing.event.EventListenerList;

import fr.univ_tln.inf9.exaplanning.api.cours.event.end_dateChangedEvent;
import fr.univ_tln.inf9.exaplanning.api.cours.event.end_dateListener;
import fr.univ_tln.inf9.exaplanning.api.cours.event.idChangedEvent;
import fr.univ_tln.inf9.exaplanning.api.cours.event.idListener;
import fr.univ_tln.inf9.exaplanning.api.cours.event.start_dateChangedEvent;
import fr.univ_tln.inf9.exaplanning.api.cours.event.start_dateListener;
import fr.univ_tln.inf9.exaplanning.api.cours.event.termChangedEvent;
import fr.univ_tln.inf9.exaplanning.api.cours.event.termListener;
import fr.univ_tln.inf9.exaplanning.api.cours.event.typeSChangedEvent;
import fr.univ_tln.inf9.exaplanning.api.cours.event.typeSListener;

/**
 * @author pivi
 *
 */
public class MetaTimeSlot {

	private int id;
	private Date start_date;
	private Date end_date;
	private int term;
	public enum TypeSlot{
		cours,td,tp,examen,conference,examen_tp,reunion
	}
	private TypeSlot typeS;
	
	private EventListenerList listeners;
	/**
	 * @param id
	 * @param start_date
	 * @param end_date
	 * @param term
	 * @param typeS
	 */
	public MetaTimeSlot(int id, Date start_date, Date end_date, int term,
			TypeSlot typeS) {
		super();
		this.id = id;
		this.start_date = start_date;
		this.end_date = end_date;
		this.term = term;
		this.typeS = typeS;
	}
	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}
	/**
	 * @param id the id to set
	 */
	public void setId(int id) {
		this.id = id;
		fireIdChanged();	
	}
	
	private void fireIdChanged() {
		idListener[] listenerList = (idListener[])listeners.getListeners(idListener.class);
		
		for(idListener listener : listenerList){
			listener.idChanged(new idChangedEvent(this, getId()));
		}	
	}
	
	public void addIdListener(idListener listener){
		listeners.add(idListener.class, listener);
	}
	
	public void removeIdListener(idListener l){
		 listeners.remove(idListener.class, l);
	}
	/**
	 * @return the start_date
	 */
	public Date getStart_date() {
		return start_date;
	}
	/**
	 * @param date_d the date_d to set
	 */
	public void setStart_date(Date start_date) {
		this.start_date = start_date;
		fireStart_dateChanged();	
	}
	
	private void fireStart_dateChanged() {
		start_dateListener[] listenerList = (start_dateListener[])listeners.getListeners(start_dateListener.class);
		
		for(start_dateListener listener : listenerList){
			listener.start_dateChanged(new start_dateChangedEvent(this, getStart_date()));
		}	
	}
	
	public void addStart_dateListener(start_dateListener listener){
		listeners.add(start_dateListener.class, listener);
	}
	
	public void removeStart_dateListener(start_dateListener l){
		 listeners.remove(start_dateListener.class, l);
	}
	
	/**
	 * @return the end_date
	 */
	public Date getEnd_date() {
		return end_date;
	}
	/**
	 * @param term the term to set
	 */
	public void setEnd_date(Date end_date) {
		this.end_date = end_date;
		fireEnd_dateChanged();
	}
	
	private void fireEnd_dateChanged() {
		end_dateListener[] listenerList = (end_dateListener[])listeners.getListeners(end_dateListener.class);
		
		for(end_dateListener listener : listenerList){
			listener.end_dateChanged(new end_dateChangedEvent(this, getEnd_date()));
		}	
	}
	
	public void addEnd_dateListener(end_dateListener listener){
		listeners.add(end_dateListener.class, listener);
	}
	
	public void removeEnd_dateListener(end_dateListener l){
		 listeners.remove(end_dateListener.class, l);
	}
	/**
	 * @return the term
	 */
	public int getTerm() {
		return term;
	}
	/**
	 * @param duree the term to set
	 */
	public void setTerm(int term) {
		this.term = term;
		fireTermChanged();
	}
	
	private void fireTermChanged() {
		termListener[] listenerList = (termListener[])listeners.getListeners(termListener.class);
		
		for(termListener listener : listenerList){
			listener.termChanged(new termChangedEvent(this, getTerm()));
		}	
	}
	
	public void addTermListener(termListener listener){
		listeners.add(termListener.class, listener);
	}
	
	public void removeTermListener(termListener l){
		 listeners.remove(termListener.class, l);
	}
	/**
	 * @return the typeC
	 */
	public TypeSlot getTypeS() {
		return typeS;
	}
	/**
	 * @param typeC the typeC to set
	 */
	public void setTypeS(TypeSlot typeS) {
		this.typeS = typeS;
		fireTypeSChanged();
	}
	
	private void fireTypeSChanged() {
		typeSListener[] listenerList = (typeSListener[])listeners.getListeners(typeSListener.class);
		
		for(typeSListener listener : listenerList){
			listener.typeSChanged(new typeSChangedEvent(this, getTypeS()));
		}	
	}
	
	public void addTypeSListener(typeSListener listener){
		listeners.add(typeSListener.class, listener);
	}
	
	public void removeTypeSListener(typeSListener l){
		 listeners.remove(typeSListener.class, l);
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "MetaCreneau [id=" + id + ", date_d=" + start_date + ", date_f="
				+ end_date + ", duree=" + term + ", typeC=" + typeS + "]";
	}
	
	
	
}
